package com.tuozixuan.singleton1;

/**
 * 单例模式<br/>
 * 用来保证一个对象只能创建一个实例，它还提供了对实例的全局访问方法<br/>
 * 
 * 1.所有的单例构造器都要声明为私有的（private）<br/>
 * 2.再通过声明静态（static）方法实现全局访问获得该单例实例
 * @author tuozixuan
 *
 */
public class Singleton {
	
	private static Singleton instance;
	
	private Singleton() {
		System.out.println("Something is Instantiated.");
	}
	
	public static Singleton getInstance() {
		if (instance == null) {
			instance = new Singleton();
		}
		return instance;
	}
	
	public void doSomething() {
		System.out.println("Something is Done.");
	}
}
